
<%-- P241貸出画面 --%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ page import="java.sql.*,book.BookBean" %>
<%
	session.setAttribute("stage","2");
	request.setCharacterEncoding("UTF-8");
%>
<%
	BookBean book = (BookBean)request.getAttribute("book");						    //書籍ID

	int stock_books = (Integer)request.getAttribute("stock_books");				    //所蔵数
	int rental_books = (Integer)request.getAttribute("rental_books");				//貸出中冊数
	int reserve_books = (Integer)request.getAttribute("reserve_books");			    //予約数
	int rental_numberbooks = (Integer)request.getAttribute("rental_numberbooks");	//貸出可能冊数
	String rental_date = (String)request.getAttribute("rental_date");				//貸出日
	String return_plan_date = (String)request.getAttribute("return_plan_date");		//返却予定日
	String reserve_id = (String)request.getAttribute("reserve_id");		//予約ID
	String member_id = (String)request.getAttribute("member_id");		//利用者ID
	String error_message = "※ﾕｰｻﾞ管理IDを入力してください" ;
	String error2 = (String)request.getAttribute("error2");
	String msg = (String)request.getAttribute("msg");

%>

<c:import url="/share/layout.jsp">
	<c:param name="title" value="書籍貸出" />
	<c:param name="css" value="book.css"/>
	<c:param name="content">
		<jsp:attribute name="value">


<!--contents start -->
<% if(msg != null && !"".equals(msg)) { %>
<div id="msg_servlet" class="msg_javascript">
	<%= msg %>
</div>
<% } %>
<div id="msg_javascript" class="msg_javascript"></div>

<div id="userEdit">


		<table class="form_table">

			<tr>
				<td rowspan="8" style="vertical-align: top;">
					<img src="/Books/book_img/<%= book.getPicture() %>.jpg" width="200px" />
				</td>

				<th>書籍ID</th>
				<td><%= book.getId() %></td>
			</tr>
			<tr>
				<th>タイトル</th>
				<td><%=book.getTitle() %></td>
			</tr>
			<tr>
				<th>著者名</th>
				<td><%=book.getWriter() %></td>
			</tr>
			<tr>
				<th>出版者</th>
				<td><%=book.getPublisher() %></td>
			</tr>
			<tr>
				<th>ジャンル</th>
				<td><%=book.getGenre() %></td>
			</tr>
			<tr>
				<th>ISBNコード</th>
				<td><%=book.getIsbn() %></td>
			</tr>
			<tr>
				<th>発行年月日</th>
				<td><%=book.getPublicationDate() %></td>
			</tr>
			<tr>
				<th>内容</th>
				<td><%=book.getContent() %></td>
			</tr>

		   </table>

<%--在庫状況テーブル --%>

<div id="bookstock">

		<table class="form_table">
		     <caption>在庫状況</caption>
			 <tr>
			 	<th>所蔵数</th>
				<th>貸出中冊数</th>
				<th>予約数</th>
				<th>貸出可能冊数</th>
			 </tr>
			 <tr>
			 	<td align="center"><%=stock_books%></td>
				<td align="center"><%=rental_books %></td>
			 	<td align="center"><%=reserve_books%></td>
			 	<td align="center"><%=rental_numberbooks %></td>
			 </tr>
		</table>
</div>

	<form action="#" method="post">

<%--利用者情報入力テーブル --%>

<% if( rental_numberbooks > 0) { %>
<div id="bookstock">
	<!-- 表示非表示切り替え -->

		<table class="form_table">

		<caption>利用者情報入力
		</caption>
			<tr>
				<th>ユーザー管理ID</th>
				<td>
					<% if (member_id == null || "".equals(member_id)) {%>
					<input type="text" name="member_id" id="member_id" />

					<% }else{ %>

					<input type="text" name="member_id" id="member_id" value="<%=member_id %>" disabled="disabled" />
					<% } %>
					<span id="error_message" class="error_message">
						<%
						if(error2 !=null){
							out.print(error2);
						}
						%>

					</span>
				</td>
			</tr>
			<tr>
				<th>貸出日</th>
				<td>
					<%=rental_date %>
					<input type="hidden" name="rental_date" id="rental_date" value="<%=rental_date %>" />
				</td>
			</tr>
			<tr>
				<th>返却予定日</th>

				<td>
				<%=return_plan_date %>
				<input type="hidden" name="return_plan_date" id="return_plan_date"value="<%=return_plan_date%>" />
				</td>
			</tr>
		</table>

</div>
<% } %>
<%-- 表示ボタン --%>
				<div class="buttons">

				<input type="submit" value="戻る" class="button" style="cursor:pointer"
					       onClick="history.back();return false;"title="『書籍検索結果』へ"style="cursor:pointer">

				<% if( rental_numberbooks > 0) { %>
					<input type="button" value="貸出" class="button" style="cursor:pointer" onClick="kasidasi()">
				<% } %>

				</div>
	</form>
</div>

<%--ダイアログ表示 --%>
<script type="text/javascript">
	<!--
	function kasidasi(){

		var m = document.getElementById("msg_servlet");
		var e2 = document.getElementById("msg_javascript");
		var e = document.getElementById("error_message");


		// member_idを取得してｘに代入。
		var x = document.getElementById("member_id").value;

		if (x == "") {
			if (m != null) {
				m.innerHTML = "";
			}
			e2.innerHTML = "ユーザー管理IDを入力して下さい";
			e.innerHTML = "※";
		}
		else {
			e2.innerHTML = "";
			e.innerHTML = "";

			ret = confirm("書籍ID:<%= book.getId() %>" + " 【<%=book.getTitle() %>】" + "を貸出しますか？");

			if (ret == true){
				var v = "/Books/book/RentalServlet?book_id=<%=book.getId() %>&member_id=" + x + "&rental_date=<%=rental_date %>&return_plan_date=<%=return_plan_date%>&reserve_id=";
				<% if (reserve_id != null) { %>
					v = v + "<%=reserve_id%>";
				<% } %>
				v = v + "&book_isbn=<%=book.getIsbn() %>";
			    location.href = v;
			}

		}
	}
	// -->
</script>

<!-- contents end -->
		</jsp:attribute>
	</c:param>
</c:import>


